package main

import (
	"fmt"
	"net/http"
	"github.com/gorilla/mux"
)

func main() {
	// 创建新的rolla/mux路由
	r := mux.NewRouter()

	// 创建 Handler 并注册到路由
	r.HandleFunc("/books/{title}/page/{page}", func(w http.ResponseWriter, r *http.Request) {
		vars := mux.Vars(r)
		title := vars["title"]
		page := vars["page"]

		fmt.Fprintf(w, "You've requested the book: %s on page %s\n", title, page)
	})

	fmt.Println( "example url : ip:8080/books/test_title/page/100")
	// 监听8080端口，并使用rolla/mux 路由启动服务
	http.ListenAndServe(":8080", r)
}
